import sqlite3 from 'sqlite3' 

class Sqlite{

  constructor(dbpath) {
    const sqlite = sqlite3.verbose()
    this.db = new sqlite.Database(dbpath)
  }

  get(sql, placeholders = []) {
    return new Promise((resolve, reject) => 
      this.db.get(sql, placeholders, (err, row) => err ? reject(err) :  resolve(row))
    )
  }

  run(sql, placeholders = []) {
    const db = this.db
    console.log(sql, placeholders);
    return new Promise((resolve, reject) => 
      db.run(sql, placeholders, function (err){
        err ? reject(err) : resolve(this)
      })
    )
  }
}

export default dbpath => new Sqlite(dbpath)